require.sync("ActivityStatusEnum");
Ext.define('App.controller.activity.ActivityViewController', {
	extend : 'Ext.app.ViewController',
	alias : 'controller.activityViewController',
	menu : Ext.widget('menu'),
	control : {
		'activityView activityList' : {
			beforerender : function(grid) {
				var buttons = {
					'bs/activity/saveActivity' : function(permit) {
						BaseUtil.createView('activity.ActivityWindow',permit,{storeId:'activity.ActivityStore'}).show();
					}
				};
				BaseUtil.createPermitTbar(grid, buttons);
			},
			itemcontextmenu : function(view, record, item, index, e) {
				var id = record.get('id');
				var menuitems = {
					'bs/activity/updateActivity' : function(permit) {
						var win = BaseUtil.createView('activity.ActivityWindow',permit,{storeId:'activity.ActivityStore'});

                        var imgPath=win.down("[name=homeImagePath]");
                        var logoPath=win.down("[name=homeImageLogosPath]");

                        imgPath.setVisible(true);
                        logoPath.setVisible(true);

                        var imgBtn = win.down('[name=btn1]');
                        var img=win.down("[name=homeImages]");
                        var imgBtn2 = win.down('[name=btn2]');
                        var img2=win.down("[name=homeImageLogos]");
                        var number=win.down("[name=number]");

                        imgBtn.setVisible(true);
                        img.setVisible(false);
                        imgBtn2.setVisible(true);
                        img2.setVisible(false);
                        if(imgPath!='') {
                            img.setDisabled(true);
                        }
                        if(logoPath!='') {
                            img2.setDisabled(true);
                        }
                        if(number!=''){
                            number.setHidden(false);
                        }
                        win.down('form').loadRecord(record);
                        win.show();
					}
				};
				var status = record.get('status'),store = Ext.StoreMgr.get('activity.ActivityStore');
				var activityStatus = record.get('activityStatus'),store = Ext.StoreMgr.get('activity.ActivityStore');
				if(activityStatus === ActivityStatusEnum.PUBLISHED.getValue()){
					menuitems['bs/activity/updateActivityStatus'] = function(permit) {
						BaseUtil.statusConfirm('确认下架此活动吗?',permit.url,id,store);
					}
				}
				/*else{
					menuitems['bs/activity/removeActivity'] = function(permit) {
						BaseUtil.statusConfirm('确认删除此记录吗?',permit.url,id,store);
					}
				}*/
				BaseUtil.createPermitMenu(view, this.menu, e, menuitems);
			},
			render : function() {
				BaseUtil.loadStore(Ext.StoreMgr.get('activity.ActivityStore'),Ext.getCmp('activityView').down('activitySearch form').getForm().getFieldValues());
			}
		},
		'activityView activitySearch [action=search] ' : {
			click : function() {
				BaseUtil.loadStore(Ext.StoreMgr.get('activity.ActivityStore'),Ext.getCmp('activityView').down('activitySearch form').getForm().getFieldValues());
			}
		}
	}
});